package com.paw.kafka.elk.controller;

import java.util.Random;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import com.paw.kafka.elk.service.MetricService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lvzihai
 * @date 2021/7/26
 **/
@Slf4j
@RestController
public class KafkaLogController {


  @Autowired
  private MetricService metricService;

  @GetMapping("/kafka")
  public String kafka(){
    int time = RandomUtil.randomInt(0, 100);
    ThreadUtil.sleep(time);
    String value = time/10+"";
    String[] tags =  new String[]{"segment",value};
    metricService.registerCounterMetric("kafka",tags).increment();
    // 柱状图  BarGauge
    metricService.registerHistogramMetric("PAY_ORDER_TIME", new long[]{5, 15, 30},"type","aliPay").record(RandomUtil.randomInt(0, 30));

    log.info("cost time: "+time);
    log.debug("debug time: "+time);

    return "cost time: "+time;
  }
}
